package com.gardenguell.salad.ui.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.gardenguell.salad.R;
import com.gardenguell.salad.data.client.SaladClient;
import com.gardenguell.salad.data.volley.OnErrorResponse;
import com.gardenguell.salad.data.volley.OnSuccessResponse;
import com.gardenguell.salad.ui.activity.base.BaseActivity;
import com.gardenguell.salad.ui.activity.base.ToolbarActivity;

public class RegisterActivity extends BaseActivity{

    private TextView userNameTv;
    private TextView passwordTv;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        userNameTv = (TextView)findViewById(R.id.tv_first);
        passwordTv = (TextView)findViewById(R.id.tv_second);

        userNameTv.setHint(R.string.input_username);
        passwordTv.setHint(R.string.input_password);

        userNameTv.setText("test");
        passwordTv.setText("test");


    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch(v.getId()){
            case R.id.btn_register:
                SaladClient saladClient = new SaladClient();
                String username = userNameTv.getText().toString().trim();
                String password = passwordTv.getText().toString().trim();
                saladClient.register(username, password, new OnSuccessResponse() {
                    @Override
                    public void onSuccessWithNoBody() {
                        super.onSuccessWithNoBody();
                        Toast.makeText(RegisterActivity.this.getBaseContext(), R.string.register_success_tip, Toast.LENGTH_SHORT).show();
                        finish();
                    }
                }, this);
                break;
            case R.id.btn_back:
                finish();
                break;
            default:
                break;
        }
    }
}
